import axios from "axios";
import { ISearch, IGetAction } from "./interface";
const search: ISearch = {
  namespaced: true,
  state: {
    res: [],
  },
  actions: {
    async getres({ commit }, { value }) {
      const res: Array<string> = await axios(
        `/index.php?r=index/kwarr&kw=${value}&token=false`
      ).then((res): Array<string> => {
        console.log(res);
        return res.data.data;
      });
      const action: IGetAction = {
        type: "GETRES",
        payload: res,
      };
      commit(action);
    },
  },
  mutations: {
    GETRES(state, action) {
      state.res = action.payload;
    },
  },
};
export default search;
